<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  <div id="test">
    <input type="text" v-model="firstName"><br>
    <input type="text" v-model="lastName"><br>
    <p>(插值){{firstName+'-'+lastName}}</p>
    <p>（方法）{{firstName2()}}</p>
    <p>（方法）{{firstName2()}}</p>
    <p>（方法）{{firstName2()}}</p>
    <p>（计算属性）{{firstName3}}</p>
    <p>（计算属性）{{firstName3}}</p>
    <p>（计算属性）{{firstName3}}</p>
    <p>（监视）{{fullName}}</p>
  </div>

  <script src="../js/vue.js"></script>
  <script>
    const vm = new Vue({
      el: "#test",
      data: {
        firstName:'A',
        lastName:'B',
        fullName:'A-B'
      },
      methods:{
        firstName2(){
          console.log('11');
          return this.firstName+'-'+this.lastName
        }
      },
      computed:{
        firstName3(){
          console.log('22');
          return this.firstName+'-'+this.lastName
        }
      },
      watch:{
        firstName:{
          handler:function(newValue,oldValue){
            console.log('33');
            this.fullName = newValue+'-'+this.lastName
          }
        }
      },
    })
    vm.$watch('lastName',function(newValue,oldValue){
      console.log('444');
      this.fullName = this.firstName+'-'+newValue
    })
  </script>
</body>
</html>